package com.mvpandroiddemo.view;

import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.mvpandroiddemo.R;
import com.mvpandroiddemo.utils.DensityUtil;

/**
 * @Description $description$
 * @Author owner
 * @CreateTime 2019/10/17 10:52
 **/
public class LoadingDialog extends AlertDialog {

    private Context mContext;

    public LoadingDialog(@NonNull Context context) {
        super(context, R.style.LoadingDialog);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_progress);
        setCanceledOnTouchOutside(true);

    }

    @Override
    public void show() {
        super.show();
        Window dialogWindow = this.getWindow();
        if (dialogWindow != null) {
            WindowManager.LayoutParams layoutParams = dialogWindow.getAttributes();
            int newWidth = DensityUtil.dp2px(mContext, 200);
            if (layoutParams.width != newWidth) {
                layoutParams.height = layoutParams.width = newWidth;
                dialogWindow.setAttributes(layoutParams);
            }
        }
    }
}
